using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ObjectLib;

namespace ObjectParser
{
	/// <summary>
	/// Summary description for ConPropertiesDialog.
	/// </summary>
	public class ConPropertiesDialog : System.Windows.Forms.Form
    {
		private System.Windows.Forms.Button butOK;
        private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox textPigBor;
		private System.Windows.Forms.TextBox textPigStripe;
        private System.Windows.Forms.TextBox textSpec;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox textShad;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.TextBox textBevel;
		public ContourF Contour;

		public ConPropertiesDialog(ContourF Contour)
		{
			InitializeComponent();

			this.Contour = Contour;
			this.textBevel.Text = Convert.ToString(Contour.CatData.Bevel);
            this.textPigBor.Text = Convert.ToString(Contour.CatData.PigmentBorder);
            this.textPigStripe.Text = Convert.ToString(Contour.CatData.PigmentStripe);
            this.textShad.Text = Convert.ToString(Contour.CatData.ShadowBorder);
            this.textSpec.Text = Convert.ToString(Contour.CatData.SpecularBorder);
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.butOK = new System.Windows.Forms.Button();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.textPigBor = new System.Windows.Forms.TextBox();
            this.textPigStripe = new System.Windows.Forms.TextBox();
            this.textSpec = new System.Windows.Forms.TextBox();
            this.label10 = new System.Windows.Forms.Label();
            this.label11 = new System.Windows.Forms.Label();
            this.textShad = new System.Windows.Forms.TextBox();
            this.label12 = new System.Windows.Forms.Label();
            this.textBevel = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // butOK
            // 
            this.butOK.Location = new System.Drawing.Point(4,182);
            this.butOK.Name = "butOK";
            this.butOK.Size = new System.Drawing.Size(268,23);
            this.butOK.TabIndex = 2;
            this.butOK.Text = "OK";
            this.butOK.Click += new System.EventHandler(this.butOK_Click);
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(-5,64);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(214,23);
            this.label4.TabIndex = 5;
            this.label4.Text = "Weak (1) to Strong (3) Pigment Border:";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(4,156);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(205,23);
            this.label5.TabIndex = 6;
            this.label5.Text = "Weak (1) to Strong (3) Specular Border:";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(1,96);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(208,23);
            this.label7.TabIndex = 8;
            this.label7.Text = "Weak (1) to Strong (3) Pigment Stripe:";
            this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // textPigBor
            // 
            this.textPigBor.Location = new System.Drawing.Point(209,64);
            this.textPigBor.Name = "textPigBor";
            this.textPigBor.Size = new System.Drawing.Size(63,20);
            this.textPigBor.TabIndex = 11;
            // 
            // textPigStripe
            // 
            this.textPigStripe.Location = new System.Drawing.Point(209,96);
            this.textPigStripe.Name = "textPigStripe";
            this.textPigStripe.Size = new System.Drawing.Size(63,20);
            this.textPigStripe.TabIndex = 12;
            // 
            // textSpec
            // 
            this.textSpec.Location = new System.Drawing.Point(209,156);
            this.textSpec.Name = "textSpec";
            this.textSpec.Size = new System.Drawing.Size(63,20);
            this.textSpec.TabIndex = 13;
            // 
            // label10
            // 
            this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif",8.25F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(0)));
            this.label10.Location = new System.Drawing.Point(4,-2);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(268,24);
            this.label10.TabIndex = 17;
            this.label10.Text = "Integers (1 to 3), 0 = uncategorized:";
            this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // label11
            // 
            this.label11.Location = new System.Drawing.Point(-2,126);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(211,23);
            this.label11.TabIndex = 18;
            this.label11.Text = "Weak (1) to Strong (3) Shadow Boundary:";
            this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // textShad
            // 
            this.textShad.Location = new System.Drawing.Point(209,126);
            this.textShad.Name = "textShad";
            this.textShad.Size = new System.Drawing.Size(63,20);
            this.textShad.TabIndex = 19;
            // 
            // label12
            // 
            this.label12.Location = new System.Drawing.Point(-2,32);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(211,23);
            this.label12.TabIndex = 20;
            this.label12.Text = "Shallow (1) to Deep (3) Beveling:";
            this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // textBevel
            // 
            this.textBevel.Location = new System.Drawing.Point(209,32);
            this.textBevel.Name = "textBevel";
            this.textBevel.Size = new System.Drawing.Size(63,20);
            this.textBevel.TabIndex = 21;
            // 
            // ObjPropertiesDialog
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5,13);
            this.ClientSize = new System.Drawing.Size(277,209);
            this.Controls.Add(this.textBevel);
            this.Controls.Add(this.label12);
            this.Controls.Add(this.textShad);
            this.Controls.Add(this.label11);
            this.Controls.Add(this.label10);
            this.Controls.Add(this.textSpec);
            this.Controls.Add(this.textPigStripe);
            this.Controls.Add(this.textPigBor);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.butOK);
            this.Name = "ObjPropertiesDialog";
            this.Text = "Contour Properties";
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion
		private void butOK_Click(object sender, System.EventArgs e)
		{
			bool proceed = true;

			int bevel =Contour.CatData.Bevel;
			int pigbor=Contour.CatData.PigmentBorder;
			int pigstripe = Contour.CatData.PigmentStripe;
			int shad = Contour.CatData.ShadowBorder;
            int spec = Contour.CatData.SpecularBorder;

			try{	bevel = Convert.ToInt32(this.textBevel.Text); }
			catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textBevel.Focus(); }

			if(proceed)
			{
				try{	pigbor = Convert.ToInt32(this.textPigBor.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textPigBor.Focus(); }
			}

			if(proceed)
			{
				try{	pigstripe = Convert.ToInt32(this.textPigStripe.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textPigStripe.Focus(); }
			}

			if(proceed)
			{
				try{	shad = Convert.ToInt32(this.textShad.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textShad.Focus(); }
			}
			if(proceed)
			{
				try{	spec = Convert.ToInt32(this.textSpec.Text); }
				catch{	proceed=false; MessageBox.Show(this, "Value was not an integer."); this.textSpec.Focus(); }
			}
            if(proceed && (bevel>3 || bevel<0)) { this.textBevel.Focus(); proceed=false; MessageBox.Show("Value was out of range."); }
            if(proceed && (pigbor>3 || pigbor<0)) { this.textPigBor.Focus(); proceed=false; MessageBox.Show("Value was out of range."); }
            if(proceed && (pigstripe>3 || pigstripe<0)) { this.textPigStripe.Focus(); proceed=false; MessageBox.Show("Value was out of range."); }
            if(proceed && (shad>3 || shad<0)) { this.textShad.Focus(); proceed=false; MessageBox.Show("Value was out of range."); }
            if(proceed && (spec>3 || spec<0)) { this.textSpec.Focus(); proceed=false; MessageBox.Show("Value was out of range."); }
			if(proceed)
			{
                Contour.CatData.Bevel = bevel;
                Contour.CatData.PigmentBorder = pigbor;
                Contour.CatData.PigmentStripe = pigstripe;
                Contour.CatData.ShadowBorder = shad;
                Contour.CatData.SpecularBorder = spec;

				this.DialogResult = DialogResult.OK;
				this.Close();
			}
			else
				this.DialogResult = DialogResult.Cancel;
		}
	}
}